const { getAll, add, update, remove } = require('../../utils/dbTools');
const tableName = "reply";

/**
 * 获取评论列表
 * 
*/
const replyList = async (req, res) => {
    const output = {
        code: 200,
        msg: '操作成功'
    }
    const { pid, page, size } = req.query;
    console.log(pid, page, size,123);
    if (!pid || !page || !size) {
        output.code = 500;
        output.msg = "参数错误";
        return res.send(output);
    }
    const result = await getAll(tableName, { pid, page, size });
    if (!result) {
        output.code = 500;
        output.msg = "操作失败";
        return res.send(output);
    }
    output.data = result;
    res.send(output);
}

/**
 * 删除评论
*/
const replyRemove = async (req, res) => {
    const output = {
        code: 200,
        msg: '操作成功'
    }
    const { id } = req.query;
    if (!id) {
        output.code = 500;
        output.msg = "操作失败";
        return res.send(output);
    }
    const result = await remove(id, table);
    if (!result) {
        output.code = 500;
        output.msg = "操作失败";
        return res.send(output);
    }
    res.send(output);
}

module.exports = {
    replyList,
    replyRemove
}